var RM001 = {};

RM001.loadDataTable = function(isSearch) {
    
        $('#dataTable')
	    .dataTable(
		    {
			bDestroy : true,
			bProcessing : false,
			bServerSide : true, 
			bLengthChange : false,
			bFilter : false,
//			"bJQueryUI": true,
			sAjaxSource : "getRM001DataTable",
			fnServerParams : function(aoData) {
			  
			    aoData.push(
				    /*---- For Tower Search ----*/
				    {
        				"name" : "model.tower.tower",
        				"value" : $('#tower').val()
				    }, {
					"name" : "model.tower.floor",
					"value" : $('#floor').val()
				    }, {
					"name" : "model.tower.unitNo",
					"value" : $('#unitNo').val()
				    }, {
					"name" : "model.tower.address",
					"value" : $('#address').val()
				    }, 
				    /*---- For Other Search ----*/
				    {
        				"name" : "model.accridusrno",
        				"value" : $('#accridusrno').val()
				    }, {
					"name" : "model.accrcrdid",
					"value" : $('#accrcrdid').val()
				    }, {
					"name" : "model.accrlrno",
					"value" : $('#accrlrno').val()
				    }, {
					"name" : "model.accrstat",
					"value" : $('#status').val()
				    });
			},
			columns : [ {
			    "data" : "accrid",
			    "sClass" : "center"
			}, {
			    "data" : "accridusrno",
			    "sClass" : "center"
			}, {
			    "data" : "accrcrdid",
			    "sClass" : "center"
			}, {
			    "data" : "accrlrno" ,
			    "sClass" : "center"
			}, {
			    "data" : "tower.tower",
			    "sClass" : "center"
			}, {
			    "data" : "tower.floor",
			    "sClass" : "center"
			}, {
			    "data" : "tower.unitNo",
			    "sClass" : "center"
			}, {
			    "data" : "tower.address",
			    "sClass" : "center"
			}, {
			    "data" : "accrstat",
			    "sClass" : "center"
			} ],
			aaSorting: [[1, 'asc']]
			,
        		columnDefs : [
        			{
        			    render : function(data, type, row) {
        				return  data? data : ' - ';
        			    },
        			    targets : 2
        			},
        			{
        			    render : function(data, type, row) {
        				return  data? data : ' - ';
        			    },
        			    targets : 3
        			},
        			{
        			    render : function(data, type, row) {
        				return _COMMON.StatusRender[data];
        			    },
        			    targets : 8
        			},
        			{
        			    render : function(data, type, row) {
        				return _COMMON.ButtonRender.editBtn(
        					'RM001.onEdit(\'' + data + '\')',
        					null)
        					+ '&nbsp;'
        					+ _COMMON.ButtonRender.delBtn(
        						'RM001.onDelete(\'' + data
        							+ '\')',
        						_COMMON.isAccountHide);
        			    },
        			    targets : 0
        			}, {
        			    'bSortable' : false,
        			    'aTargets' : [ 0 ]
			} ],
        });
    
};

RM001.clearHeaderCriteria = function(obj){
    
// $.each(obj, function(val, itm) {
// $('#'+itm).reset();
//    });
    $('#cardPlate').clear();
    $('#longRangeNo').clear();
    $('#userNo').clear();
    $('#status').clear();
    
    _COMBOBOX.ResetAllTowerCriteria('tower', 'floor' , 'unit' , 'address');
};


RM001.onDelete = function(name) {

    $("#confirm").html("Do you want to delete ?");

    $("#confirm").dialog({
        resizable: false,
        modal: true,
        title: "Confirm Delete",
        height: 180,
        width: 300,
        buttons: {
            "Yes": function () {
                $(this).dialog('close');
                location = 'RM001ADelete?cardId='+name;
            },
                "No": function () {
                $(this).dialog('close');
            }
        }
    });
};

RM001.onEdit = function(id) {
    location = 'RM001Aedit?cardId='+id;
};

RM001.init = function() {
    
    _COMBOBOX.TowerFloorUnitAddrCombo('tower', 'floor' , 'unit' , 'address'); // Load Tower Criteria Combobox
    _COMBOBOX.StatusCombo('status');
};

RM001.getSearch = function(){
	RM001.loadDataTable(true);
};

$(document).ready(function() {
    
    RM001.init();
    
    RM001.loadDataTable();
    
    $("#btnClear").click(function() {
	RM001.clearHeaderCriteria();
    });
    
    
});

